package application.view 
{
	import application.ApplicationFacade;
	import application.model.resourceProxy;
	import application.util.ResourceUtil;
	import application.view.components.MenuComponent;
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * ...
	 * @author dragonWorrior
	 */
	public class MenuMediator extends Mediator 
	{
		public static const NAME:String = "menu_mediator";
		public static const ADD_MENU:String = "add_menu";
		
		private var _menu:MenuComponent;
		private var appStage:Stage;
		
		public function MenuMediator() 
		{
			super(NAME, _menu);
		}
		
		private function get main():Main
		{
			return this.viewComponent as Main;
		}
		
		override public function listNotificationInterests():Array
		{
			return new Array(ADD_MENU);
		}
		
		override public function handleNotification(notification:INotification):void 
		{
			switch(notification.getName())
			{
				case ADD_MENU:
					addMenu();
					break;
			}
		}
		
		private function addMenu():void
		{
			appStage = ResourceUtil.appStage;
			_menu = new MenuComponent();
			appStage.addChild(_menu);
			_menu.addEventListener(MenuComponent.CLICK_PRACTICE, onPractice);
			_menu.addEventListener(MenuComponent.CLICK_PRACTICE, onLevel);
			_menu.addEventListener(MenuComponent.CLICK_PRACTICE, onCount);
		}
		
		private function onPractice(e:Event):void
		{
			
			//var clickSound:Sound = new Sound(new URLRequest("sound/Click.mp3"));
			//clickSound.play();
			var resourceProxyInstance:resourceProxy = facade.retrieveProxy("Proxy") as resourceProxy;
			var clickSound:Sound = resourceProxyInstance.clickSound;
			clickSound.play()
		}
		
		private function onLevel(e:Event):void
		{
			
		}
		
		private function onCount(e:Event):void
		{}
	}

}